package com.bbx.taxi.client.Task;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;

import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.sdk.model.official.passanger.Officail_ComboBuild;
import com.bbx.api.sdk.model.official.passanger.Official_GetCreditBuild;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Combo;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_TC;
import com.bbx.api.sdk.model.official.passanger.Return.Official_GetCredit;
import com.bbx.api.sdk.model.official.passanger.Return.Official_Star;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.sdk.net.official.passanger.Officail_ComboNet;
import com.bbx.api.sdk.net.official.passanger.Official_AANet;
import com.bbx.api.sdk.net.official.passanger.Official_GetCreditNet;
import com.bbx.api.sdk.net.official.passanger.Official_StarNet;
import com.bbx.api.sdk.net.official.passanger.Official_TCNet;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Task.BaseAsyncTask;
import com.bbx.taxi.client.Task.MyOperateTask.OnOperateStatusListener;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.official.R;
/** 
 * @Path com.bbx.taxi.client.Task.MyGetCreditTask.java
 * @Author 严旭文
 * @Date 2016-4-13 下午3:20:12
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 * 获取支付额度
 */
public class MyGetCreditTask  {
	public static int STATUS_SUCCESS=0;
	public static int STATUS_FAIL=-1;
	private Activity context;
	public static MyGetCreditTask instance;
	public GetCreditTask mGetCreditTask;
	public interface OnGetCreditListener {
		/**
		 *获取支付额度
		 */
		public void onGetCredit(double monthAmt,double yearAmt);
	}

	static OnGetCreditListener mOnGetCreditListener = null;

	public static void setOnGetCreditListener(OnGetCreditListener l) {
		mOnGetCreditListener = l;
	}
	public static MyGetCreditTask getInstance(Activity context) {
		instance = new MyGetCreditTask(context);
		return instance;
	}
	public MyGetCreditTask(Activity context) {
		this.context = context;
		getCredit();
	
	}
	/**
	 * 获取支付额度
	 */
	public void getCredit() {
		Official_GetCreditBuild mOfficial_GetCreditBuild=new Official_GetCreditBuild(context);
		mOfficial_GetCreditBuild.uid=MyApplication.getInstance().getUid();
		GetCreditTask mGetCreditTask=new GetCreditTask(context, mOfficial_GetCreditBuild);
		mGetCreditTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	private class GetCreditTask extends BaseAsyncTask {

		private Official_GetCreditBuild mOfficial_GetCreditBuild;

		public GetCreditTask(Activity context, Official_GetCreditBuild mOfficial_GetCreditBuild) {
			super(context,true);
			this.mOfficial_GetCreditBuild = mOfficial_GetCreditBuild;
		}

		@Override
		public void onSuccess(Object object) {
			if (object != null) {
				Official_GetCredit mOfficial_GetCredit=(Official_GetCredit)object;
				if(mOfficial_GetCredit!=null){
				     if(mOnGetCreditListener!=null)mOnGetCreditListener.onGetCredit(mOfficial_GetCredit.getMonthAmt(),mOfficial_GetCredit.getYearAmt());
				}else{
					ToastUtil.showToast(context, R.string.no_network);
					if(mOnGetCreditListener!=null)mOnGetCreditListener.onGetCredit(0,0);
				}
			}else{
				ToastUtil.showToast(context, R.string.no_network);
				if(mOnGetCreditListener!=null)mOnGetCreditListener.onGetCredit(0,0);
			}
		}

		@Override
		public void onFailed(int status, String msg) {
			try {
				JSONObject jso=new JSONObject(msg);
				ToastUtil.showToast(context, jso.getString("message"));
			} catch (JSONException e) {
				e.printStackTrace();
			}
			if(mOnGetCreditListener!=null)mOnGetCreditListener.onGetCredit(0,0);
		}

		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(mOfficial_GetCreditBuild).getJson();
			return new Official_GetCreditNet(context, json);
		}
	}

}
